//
//  ZJCorrelationCourseTableViewCell.m
//  ShangHaiHuDongApp
//
//  Created by ZJ on 2017/6/30.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "ZJCorrelationCourseTableViewCell.h"
#import "StudyCoureVideoViewController.h"

/** 视频、音频cell */
#import "ZJStudyVideoTableViewCell.h"
/** 图书cell */
#import "ZJStudyBookTableViewCell.h"
#define videoCell @"ZJStudyVideoTableViewCell"
#define bookCell  @"ZJStudyBookTableViewCell"
@interface ZJCorrelationCourseTableViewCell ()<UITableViewDelegate,UITableViewDataSource>
/** tableView */
@property (nonatomic, strong) UITableView *tableView;

@end

@implementation ZJCorrelationCourseTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self.contentView addSubview:self.tableView];
        
        self.tableView.sd_layout
        .topSpaceToView(self.contentView, 0)
        .leftSpaceToView(self.contentView, 0)
        .rightSpaceToView(self.contentView, 0)
        .bottomSpaceToView(self.contentView, 0);
        
        
    }
    return self;
}

#pragma mark - UITableView 协议方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ZJStudyRecommendModel * model = self.dataArray[indexPath.row];
    if ([model.COURSETYPE isEqualToString:@"4"]) {//悦读会
        ZJStudyBookTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:bookCell forIndexPath:indexPath];
        cell.model = model;
        return cell;
    }else{
        
        ZJStudyVideoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:videoCell forIndexPath:indexPath];
        cell.model = model;
        return cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    ZJStudyRecommendModel *model = self.dataArray[indexPath.row];
    if ([model.COURSETYPE isEqualToString:@"4"]){//悦读会
        return 125 * [UIScreen zj_screenHScale];//图书
    }
    return 120 * [UIScreen zj_screenHScale];//视频、音频
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.delegate) {
        [self.delegate ZJCorrelationCourseTableViewCellDelegate_model:self.dataArray[indexPath.row]];
    }
}


#pragma mark - Setter

- (void)setDataArray:(NSArray *)dataArray{
    _dataArray = dataArray;
    [self.tableView reloadData];
}

#pragma mark - Getters
- (UITableView *)tableView{
    if (_tableView == nil){
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen zj_screenWith], 100) style:UITableViewStylePlain];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView  registerClass:[UITableViewCell class] forCellReuseIdentifier: @"Cell"];
        [_tableView  registerClass:[ZJStudyVideoTableViewCell class] forCellReuseIdentifier: videoCell];
        [_tableView  registerClass:[ZJStudyBookTableViewCell class] forCellReuseIdentifier: bookCell];

        _tableView.scrollEnabled = NO;
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(12 * [UIScreen zj_screenWScale], 0, [UIScreen zj_screenWith] - 24 * [UIScreen zj_screenWScale], 44 * [UIScreen zj_screenHScale])];
        label.text = @"相关课程";
        label.textColor = [UIColor textBlackColor];
        label.font = [UIFont titleTextFont];
        UIView *tableHeadview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen zj_screenWith], 44 * [UIScreen zj_screenHScale])];
        [tableHeadview addSubview:label];
        
        _tableView.tableHeaderView = tableHeadview;
        
    }
    return _tableView;
}




@end
